package com.kasax.plugin.app.visitor.moduleinit

import org.objectweb.asm.MethodVisitor
import org.objectweb.asm.Opcodes
import org.objectweb.asm.commons.AdviceAdapter

class ModuleInitMethodVisitor extends AdviceAdapter {

    final String className

    protected ModuleInitMethodVisitor(MethodVisitor mv, String className) {
        super(Opcodes.ASM7, mv, Opcodes.ACC_PUBLIC, "onCreate", "()V")
        this.className = className
    }

    @Override
    protected void onMethodEnter() {
        super.onMethodEnter()

        // 插入初始化调用
        mv.visitLdcInsn(className.replace("/", "."))
        mv.visitMethodInsn(INVOKESTATIC,
                "com/kasax/basiclib/ModuleInitHelper",
                "invokeModuleInits", "(Ljava/lang/String;)V", false
        )
    }
}